package oa.service.impl;

import java.util.Collection;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import oa.dao.ForumManageDao;
import oa.domain.forum.Forum;
import oa.domain.page.PageBean;
import oa.service.ForumManageService;
import oa.util.HQLHelper;

@Service("forumManageService")
public class ForumManageServiceImpl  implements ForumManageService{

	@Resource(name="forumManageDao")
	private ForumManageDao forumManageDao;
	
	@Override
	public Collection<Forum> getAllForum() {
		// TODO Auto-generated method stub
		return this.forumManageDao.getAllEntry();
		
	}

	@Override
	@Transactional(readOnly=false)
	public void saveForum(Forum forum) {
		// TODO Auto-generated method stub
		this.forumManageDao.saveEntity(forum);
	}

	@Override
	public Forum getForumById(Long id) {
		// TODO Auto-generated method stub
		return this.forumManageDao.getEntryById(id);
	}

	@Override
	@Transactional(readOnly=false)
	public void upateForum(Forum forum) {
		// TODO Auto-generated method stub
		this.forumManageDao.updateEntry(forum);
	}

	@Override
	@Transactional(readOnly=false)
	public void deleteForum(Long id) {
		// TODO Auto-generated method stub
		this.forumManageDao.deleteEntry(id);
	}

	@Override
	@Transactional(readOnly=false)
	public void moveUp(Long id) {
		// TODO Auto-generated method stub
		
		String hql = "from Forum f where f.position < ? order by f.position desc";
		this.forumManageDao.move(id, hql);
	}

	@Override
	@Transactional(readOnly=false)
	public void moveDown(Long id) {
		// TODO Auto-generated method stub
		String hql = "from Forum f where f.position > ? order by f.position";
		this.forumManageDao.move(id, hql);
	}

	/**
	 *分页查询
	 */
	@Override
	public PageBean getPageBean(HQLHelper hh, int currentPage) {
		// TODO Auto-generated method stub
		return this.forumManageDao.getPageBean(hh, currentPage);
	}

}
